<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%photo_group}}".
 *
 * @property string $id
 * @property string $name 相册名称
 * @property string $description 相册描述
 * @property int $photo_num 图片数量
 * @property int $created_at 添加时间
 * @property int $updated_at 修改时间
 */
class PhotoGroup extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%photo_group}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'created_at', 'updated_at'], 'required'],
            [['photo_num', 'created_at', 'updated_at'], 'integer'],
            [['name'], 'string', 'max' => 50],
            [['description'], 'string', 'max' => 255],
        ];
    }

    /**
     * 设置自动时间戳
     * @return array
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'name' => '相册名称',
            'description' => '相册描述',
            'photo_num' => '图片数量',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    public static function dropDown()
    {
        $data = self::find()->asArray()->all();
        $data_list = ArrayHelper::map($data, 'id', 'name');
        return $data_list;
    }

    public static function dropDownAll()
    {
        $drop_list = self::dropDown();
        $drop_list[''] = '全部相册';
        ksort($drop_list);
        return $drop_list;
    }
}
